'MeaMod Playme
'Developed by The MeaMod Group
'Copyright 2009 The MeaMod Group
'http://meamod.com
'by James Weston
'--------------------------------
Imports VideoLan
Imports System.Net
Imports TagLib
Imports VistaControls.TaskDialog
Imports System.Collections.ObjectModel
Imports ExceptionHandling
Imports LukeSw.Windows.Forms
Imports System.IO
Imports System.IO.Compression
Imports System.Text
Imports MeaMod_Playme.MeaMod.Dialogs
Imports System.Threading
Imports System.Runtime.InteropServices
Imports System.Reflection

Public Class frmMain
    Public Vlc As VideoLan.VideoLanClient
    Public ctlPlayer As VideoLan.VlcMediaPlayer
    Public CanPlay As Boolean
    Public CanClose As Boolean
    Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal Hwnd As Integer, ByVal wMsg As Integer, ByVal wParam As Integer, ByVal lParam As Integer) As Integer
    Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Integer
    Private Declare Function FindWindowEx Lib "user32" Alias "FindWindowExA" (ByVal hWnd1 As Integer, ByVal hWnd2 As Integer, ByVal lpsz1 As String, ByVal lpsz2 As String) As Integer
    Private Const WM_COPYDATA As Short = &H4AS
    Private CheckConn As New CheckInternetConnection()
    Private NotifierInfo As New NotifierControl.NotifierInfo
    Dim TrackName As String
    Dim AuthCode As String
    Dim ProtectedStream As String
    Dim AuthClient As New WebClient()
    Dim MuteCheck As Integer
    Dim ActivationCode As String
    Dim Adcode As String
    Public Shared TagLoc As String
    Public Shared InfoTag As TagLib.File = Nothing
    Dim PauseCheck As Boolean = False
    'Friend ctlPlayer As New LibVLC.LibVlc
    Const ConstrStrAPIKey As String = "29ecfa5468"
    Dim PlayFolder As Boolean = False
    Public noCoverArt = MeaMod_Playme.My.Resources.resNocoverartwhite
    Dim SystemTD As Long = (My.Computer.Clock.LocalTime.Year & My.Computer.Clock.LocalTime.Month)
    'Random Declarations to inizi the Class
    Dim RandomClass As New Random()
    Dim aUpdate As String = (My.Application.Info.Version.Major & "." & My.Application.Info.Version.Minor & "." & My.Application.Info.Version.Build & "." & My.Application.Info.Version.Revision)
    'Integer Stores Random Number
    Dim RandomNumber As Integer
    Dim Song As New BasicSongData
    Dim HardFailure As Boolean = False
    Dim LastTotalLength As Integer = 0
    Dim LastDuration As Integer = 0
    Dim LastFMlog() As String
    Public AdvertURL As String
    Public AdvertImage As Image
    Public w7 As New Handler(Me)
    Public SaveTag As Boolean = False
    Public NetworkCheck As Boolean = CheckConn.IsConnected()


    Private Sub frmMain_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        'If a new version is deployed, upgrade the settings.
        Try
            If My.Settings.CallSettingsUpgrade = True Then
                My.Settings.Upgrade()
                My.Settings.CallSettingsUpgrade = False
                My.Settings.LastUpdate = SystemTD
            End If
        Catch ex As Exception
            HandledExceptionManager.ShowDialog("MeaMod Playme could not update it's settings file this is because you computer does not have the Microsoft .NET SP1 update", _
                   "When you update MeaMod Playme it will not retain it's settings", _
                   "Please visit http://microsoft.com/net to download and update to the latest version of Microsoft .NET", _
                   ex, _
                    MessageBoxButtons.OK, _
                   MessageBoxIcon.Error,
                   HandledExceptionManager.UserErrorDefaultButton.Default)
        Finally
            My.Settings.CallSettingsUpgrade = False
        End Try

        Dim Setpath As String = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\" + My.Application.Info.CompanyName + "\" + My.Application.Info.AssemblyName + "\OCDS.cfg"
        '"--audio-visual=visual", 
        Dim strInitOptions As String() = {"--audio-visual=none", "--no-one-instance", "--no-loop", "--no-drop-late-frames", "--disable-screensaver", "--no-spu", "--no-osd", "--no-sub-autodetect-file", "--config=" + Setpath, "--save-config"}
        Vlc = New VideoLanClient(Environment.CurrentDirectory, strInitOptions)
        ctlPlayer = Vlc.NewMediaPlayer(pbPlayer.Handle)
        AddHandler ctlPlayer.TimeChanged, AddressOf VlcPlayer_TimeChanged
        AddHandler ctlPlayer.PositionChanged, AddressOf VlcPlayer_PositionChanged
        AddHandler ctlPlayer.StateChanged, AddressOf VlcPlayer_StateChanged

        If My.Application.CommandLineArgs.Contains("/skipnetcheck") Then
        Else
            If NetworkCheck = False Then
                frmInternetload.ShowDialog()
            End If
        End If

        Dim AUfix As Long
        My.Settings.Reload()
        AUfix = My.Settings.LastUpdate + My.Settings.UpdateInterval
        If My.Settings.AutoUpdate = True Then
            If AUfix <= SystemTD Then
                If CStr(CheckConn.IsConnected()) = True Then
                    wbAutoUpdate.Navigate("http://update.meamod.com/meamodplayme/update/version/?id=" & RandomClass.Next(1000000, 999999999))
                End If
            End If
        End If

        If My.Settings.AdvertDisable = False And NetworkCheck = True Then
            pbAdvert.Visible = True
            frmAbout.pbAdvert.Visible = True
            AdvertImage = GetAdvert("http://download.meamod.com/meamodplayme/promo/playme.mimg?id=" & RandomClass.Next(1000000, 999999999))
            AdvertURL = GetAdvertUrl("http://download.meamod.com/meamodplayme/promo/playme.mtext?id=" & RandomClass.Next(1000000, 999999999))
            pbAdvert.Image = AdvertImage
            frmAbout.pbAdvert.Image = AdvertImage
        Else
            pbAdvert.Visible = False
            frmAbout.pbAdvert.Visible = False
        End If

        If My.Settings.MediaRemote = False Then
            niControl.Visible = False
        ElseIf My.Settings.MediaRemote = True Then
            niControl.Visible = True
        End If

        If General.isWindows7 = True And My.Settings.Windows7 = True Then
            Microsoft.WindowsAPICodePack.Taskbar.TaskbarManager.Instance.ThumbnailToolbars.AddButtons(Me.Handle, w7.buttonOpen, w7.buttonPlay, w7.buttonStop)
        End If

        SetTheme()

        If My.Application.CommandLineArgs.Contains("/eac") Then
            niControl.Visible = False
            Me.WindowState = FormWindowState.Minimized
            Me.ShowInTaskbar = False
            Me.Enabled = False
            Me.Visible = False
            frmEAC.Show()
            'GoTo 1
        ElseIf My.Application.CommandLineArgs.Contains("/mmr") Then
            niControl.Visible = False
            Me.WindowState = FormWindowState.Minimized
            Me.ShowInTaskbar = False
            Me.Enabled = False
            Me.Visible = False
            frmMywnMusicStreamer.Show()
            'GoTo 1
        End If

        If My.Settings.Lyrics = False Then
            tabcMain.Controls.Remove(tabLyrics)
        End If
        If My.Settings.TabHome = False Then
            tabcMain.Controls.Remove(tabHome)
        End If
        If My.Settings.TabPodcasts = False Then
            tabcMain.Controls.Remove(tabPodcasts)
        End If
        If My.Settings.TabYouTube = False Then
            tabcMain.Controls.Remove(tabYouTube)
        End If

        imgStreamimg.Visible = False

        wbPodcasts.Navigate("http://media.ogo.ms/podcasts")

        Try
            diaOpenFile.InitialDirectory = FileIO.SpecialDirectories.MyMusic
        Catch ex As Exception
            Try
                diaOpenFile.InitialDirectory = FileIO.SpecialDirectories.MyDocuments
            Catch ex1 As Exception
                diaOpenFile.InitialDirectory = "C:\"
            End Try
        End Try
        diaOpenFile.RestoreDirectory = True
        diaOpenFile.Filter = "All Files|*.*|OgO (*.ogo, *.ogoap, *.ogovp, *.ogop, *.ogoas)|*.ogo;*.ogoap;*.ogovp;*.ogop;*.ogoas|AVI (*.avi)|*.avi|MPEG (*.mpg, *.mpeg)|*.mpg;*.mpeg|mp3 (*.mp3)|*.mp3|MOV (*.mov)|*.mov|Flash video (*.flv)|*.flv|MPEG-4 Audio (*.m4a, *.m4b, *.m4p)|*.m4a;*.m4b;*.m4p|MPEG-4 (*.mp4)|*.mp4|NSV (*.nsv)|*.nsv|OGM (*.ogm)|*.ogm|Ogg (*.ogg)|*.ogg|PVA (*.pva)|*.pva|RealMedia (*.rm, *.ram, *.ra)|*.rm;*.ram;*.ra|WAV (*.wav)|*.wav|AAC (*.aac)|*.aac|AIFF (*.aiff)|*.aiff|ASF (*.asf)|*.asf|AU (*.au)|*.au|DTS (*.dts)|*.dts|Matroska (*.mkv, *.mka, *.mks)|*.mkv;*.mka;*.mks|Flac audio (.flac)|*.flac|DivX (.divx)|*.divx|WMV (.wmv)|*.wmv|WMA (*.wma)|*.wma|3gpp (*.3g, *.3gp, *.3gpp)|*.3g;*.3gp;*.3gpp|DV (*.dv)|*.dv|ac3/a52 (*.ac3, *.a52)|*.ac3;*.a52|XviD (*.xvid)|*.xvid|Misc. (*.pspmc, *.phonem, *.pvpvc, *.avlac)|*.pspmc;*.phonem;*.pvpvc;*.avlac"
        diaOpenFile.Title = "Open File - MeaMod Playme"
        diaOpenFile.FileName = ""

        'Dim pi As PropertyInfo = GetType(OpenFileDialog).GetProperty("AutoUpgradeEnabled") 'Fix for pre .NET 2 SP1
        'If pi IsNot Nothing Then 'Fix for pre .NET 2 SP1
        'pi.SetValue(diaOpenFile, False, Nothing) 'Fix for pre .NET 2 SP1
        'End If 'Fix for pre .NET 2 SP1
        MuteCheck = 0
        AddHandler LastfmScrobbler.ProcessEnded, AddressOf ScrobblingEnded
        If My.Settings.LastFM = True Then
            Dim t As Thread
            t = New Thread(AddressOf LastfmHandshake)
            t.Start()
        End If

        If Not My.Application.CommandLineArgs.Count = 0 Then
            OpnFile(My.Application.CommandLineArgs(0))
        End If

        My.Settings.Save()

    End Sub

    Public Function VarPtr(ByVal o As Object) As Integer
        Dim GC As System.Runtime.InteropServices.GCHandle = System.Runtime.InteropServices.GCHandle.Alloc(o, System.Runtime.InteropServices.GCHandleType.Pinned)
        Dim ret As Integer = GC.AddrOfPinnedObject.ToInt32
        GC.Free()
        Return ret
    End Function

    Private Structure COPYDATASTRUCT
        Dim dwData As Integer
        Dim cbData As Integer
        Dim lpData As Integer
    End Structure

    Public Sub SetMusicInfo(ByRef r_sArtist As String, ByRef r_sAlbum As String, ByRef r_sTitle As String, Optional ByRef r_sWMContentID As String = vbNullString, Optional ByRef r_sFormat As String = "{1} - {0}", Optional ByRef r_bShow As Boolean = True)
        If My.Settings.WLMi = True Then
            Dim udtData As COPYDATASTRUCT
            Dim sBuffer As String
            Dim hMSGRUI As Integer
            'Total length can not be longer then 256 characters!
            'Any longer will simply be ignored by Messenger.
            sBuffer = "\0Music\0" & System.Math.Abs(CInt(r_bShow)) & "\0" & r_sTitle & "\0" & r_sArtist & "\0" & r_sAlbum & "\0" & "\0 MeaMod Playme" & r_sWMContentID & "\0" & vbNullChar
            udtData.dwData = &H547S
            udtData.lpData = VarPtr(sBuffer)
            udtData.cbData = Len(sBuffer) * 2
            Do
                hMSGRUI = FindWindowEx(0, hMSGRUI, "MsnMsgrUIManager", vbNullString)

                If (hMSGRUI > 0) Then
                    Call SendMessage(hMSGRUI, WM_COPYDATA, 0, VarPtr(udtData))
                End If
            Loop Until (hMSGRUI = 0)
        End If
    End Sub

    Public Sub VlcPlayer_TimeChanged(ByVal sender As Object, ByVal e As TimeChangedEventArgs)
        'tArg and tProp should be the same value but they are not.  use tProp for now
        'Dim tArg As Long = e.Time
        Dim tProp As Long = Me.ctlPlayer.Time
        'tagTime.Text = tProp & " / " & ctlPlayer.Length
    End Sub
    Public Sub VlcPlayer_PositionChanged(ByVal sender As Object, ByVal e As PositionChangedEventArgs)
        If InvokeRequired Then
            Me.BeginInvoke(New EventHandler(Of PositionChangedEventArgs)(AddressOf VlcPlayer_PositionChanged), sender, e)
        Else
            If ctlPlayer.State = VlcState.Playing Then
                sbProcess.Value = Convert.ToInt32(ctlPlayer.Position * 1000)
                If General.isWindows7 = True And My.Settings.Windows7 = True Then
                    Microsoft.WindowsAPICodePack.Taskbar.TaskbarManager.Instance.SetProgressValue(Convert.ToInt32(ctlPlayer.Position * 10000), 10000)
                End If
                Dim tProp As Long = Me.ctlPlayer.Time
                Dim TimeHold As String = TimeString((tProp / 1000)) & " / " & TimeString((ctlPlayer.Length / 1000))
                tagTime.Text = TimeHold
                btnStopn.Enabled = True
                'lblNP.Text = "Now Playing: " & frmPlayme.InfoTag.Tag.FirstPerformer & " - " & frmPlayme.InfoTag.Tag.Title
            End If
            End If
    End Sub

    Public Sub VlcPlayer_StateChanged(ByVal sender As Object, ByVal e As StateChangedEventArgs)
        If InvokeRequired Then
            Me.BeginInvoke(New EventHandler(Of StateChangedEventArgs)(AddressOf VlcPlayer_StateChanged), sender, e)
        Else
            Select Case e.NewState
                Case VlcState.Ended, VlcState.Stopped
                    'StopEvent()
                    btnPlay.Text = "Play"
                    btnTSplay.Text = "Play"
                    niPlay.Text = "Play"
                    btnPlayn.Image = My.Resources.resStartX
                    btnPlay.Image = My.Resources.resControl_play
                    btnTSplay.Image = My.Resources.resControl_play
                    niPlay.Image = My.Resources.resControl_play
                    sbProcess.Value = 0
                    sbProcess.Enabled = False
                    Try
                        If My.Settings.LastFM = True And InfoTag.Tag.FirstPerformer.Length > 0 Then
                            LastfmScrobbler.Scrobble(Song)
                        End If
                    Catch NullPointer As Exception
                    End Try
                    If SaveTag = True Then
                        Dim instance As New SaveLyricThread
                        instance._Tag = InfoTag
                        Dim th As New Threading.Thread(AddressOf instance.Save)
                        th.Start()
                    End If
                    imgStreamimg.Enabled = False
                    imgStreamimg.Visible = False
                    tagFilename.Visible = False
                    tagTime.Visible = False
                    imgBolt.Visible = False
                    tsVideoChoice.Visible = False
                    Me.Size = New System.Drawing.Size(625, 178)
                    Call SetMusicInfo("", "", "", , , False)
                    tagArt.Image = noCoverArt
                    niCoverart.Image = noCoverArt
                    pbBuyNow.Visible = False
                    If General.isWindows7 = True And My.Settings.Windows7 = True Then
                        w7.buttonPlay.Tooltip = "Play"
                        w7.buttonPlay.Icon = My.Resources.icoPlay
                        Microsoft.WindowsAPICodePack.Taskbar.TaskbarManager.Instance.SetProgressState(Microsoft.WindowsAPICodePack.Taskbar.TaskbarProgressBarState.NoProgress, Me.Handle)
                        Microsoft.WindowsAPICodePack.Taskbar.TaskbarManager.Instance.SetOverlayIcon(Me.Handle, Nothing, Nothing)
                    End If
                Case VlcState.[Error]
                    'Handle playing error

                Case VlcState.Buffering
                    'Notify system is buffering

                Case VlcState.Playing
                    sbProcess.Enabled = True
                    btnPlay.Text = "Pause"
                    btnTSplay.Text = "Pause"
                    niPlay.Text = "Pause"
                    btnPlayn.Image = My.Resources.resPauseX
                    btnPlay.Image = My.Resources.resControl_pause
                    btnTSplay.Image = My.Resources.resControl_pause
                    niPlay.Image = My.Resources.resControl_pause
                    If General.isWindows7 = True And My.Settings.Windows7 = True Then
                        w7.buttonPlay.Tooltip = "Pause"
                        w7.buttonPlay.Icon = My.Resources.icoPause
                        Microsoft.WindowsAPICodePack.Taskbar.TaskbarManager.Instance.SetProgressState(Microsoft.WindowsAPICodePack.Taskbar.TaskbarProgressBarState.Normal)
                        Microsoft.WindowsAPICodePack.Taskbar.TaskbarManager.Instance.SetOverlayIcon(Me.Handle, My.Resources.icoPlay, "Playing")
                    End If
                    If My.Settings.VideoChoice = True Then
                        tsVideoChoice.Visible = True
                        If My.Settings.VideoPro = "YouTube" Then
                            tsVideoChoice.Image = My.Resources.resYoutube
                        ElseIf My.Settings.VideoPro = "Yahoo Music" Then
                            tsVideoChoice.Image = My.Resources.resYahoo
                        ElseIf My.Settings.VideoPro = "AOL Music" Then
                            tsVideoChoice.Image = My.Resources.resAol
                        ElseIf My.Settings.VideoPro = "MTV Video" Then
                            tsVideoChoice.Image = My.Resources.resMtv
                        ElseIf My.Settings.VideoPro = "last.fm" Then
                            tsVideoChoice.Image = My.Resources.resLastfmic
                        Else
                            tsVideoChoice.Image = My.Resources.resMisc
                        End If
                    ElseIf My.Settings.VideoChoice = False Then
                        tsVideoChoice.Visible = False
                    End If

                Case VlcState.Paused
                    btnPlay.Text = "Play"
                    btnTSplay.Text = "Play"
                    niPlay.Text = "Play"
                    btnPlayn.Image = My.Resources.resStartX
                    btnPlay.Image = My.Resources.resControl_play
                    btnTSplay.Image = My.Resources.resControl_play
                    niPlay.Image = My.Resources.resControl_play
                    If General.isWindows7 = True And My.Settings.Windows7 = True Then
                        w7.buttonPlay.Tooltip = "Play"
                        w7.buttonPlay.Icon = My.Resources.icoPlay
                        Microsoft.WindowsAPICodePack.Taskbar.TaskbarManager.Instance.SetProgressState(Microsoft.WindowsAPICodePack.Taskbar.TaskbarProgressBarState.Paused)
                        Microsoft.WindowsAPICodePack.Taskbar.TaskbarManager.Instance.SetOverlayIcon(Me.Handle, My.Resources.icoPause, "Paused")
                    End If
            End Select
        End If
    End Sub

    Private Sub wbAutoUpdate_Navigated(ByVal sender As System.Object, ByVal e As System.Windows.Forms.WebBrowserNavigatedEventArgs) Handles wbAutoUpdate.Navigated
        If aUpdate < wbAutoUpdate.DocumentText Then
            frmMeaUpdate.ShowDialog()
        End If
        My.Settings.LastUpdate = SystemTD
        My.Settings.Save()
    End Sub

    Private Sub btnExit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnExit.Click
        Close()
    End Sub

    Private Sub btnAbout_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles niAbout.Click, btnAbout.Click
        frmAbout.ShowDialog()
    End Sub

    Public Sub btnOpen_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnOpen.Click, btnOpenMenu.Click, niOpen.Click, btnOpenn.Click
        Dim DidWork As Integer = diaOpenFile.ShowDialog()
        If DidWork = DialogResult.Cancel Then
        Else
            OpnFile(diaOpenFile.FileName)
        End If
    End Sub

    Public Sub btnPlay_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnPlay.Click, niPlay.Click, btnTSplay.Click, btnPlayn.Click
        If ctlPlayer.State = VlcState.Playing Then
            btnPlay.Text = "Pause"
            btnTSplay.Text = "Pause"
            niPlay.Text = "Pause"
            btnPlayn.Image = My.Resources.resPauseX
            btnPlayn.Image = My.Resources.resPauseX
            btnPlay.Image = My.Resources.resControl_pause
            btnTSplay.Image = My.Resources.resControl_pause
            niPlay.Image = My.Resources.resControl_pause
            ctlPlayer.Pause()
        ElseIf ctlPlayer.State = VlcState.Paused Then
            btnPlay.Text = "Play"
            btnTSplay.Text = "Play"
            niPlay.Text = "Play"
            btnPlayn.Image = My.Resources.resStartX
            btnPlay.Image = My.Resources.resControl_play
            btnTSplay.Image = My.Resources.resControl_play
            niPlay.Image = My.Resources.resControl_play
            ctlPlayer.Play()
        End If
    End Sub

    Public Sub btnStop_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnStop.Click, niStop.Click, btnTSStop.Click, btnStopn.Click
        StopEvent()
    End Sub

    Private Sub btnFullscreen_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnFullscreen.Click, niFulls.Click, btnTSFullscreen.Click, btnFullscreenN.Click
        If ctlPlayer.State = VlcState.Playing Then
            Try
                'ctlPlayer.VideoOutput = frmFullscreen2.pnlFVid
                frmFscreen.Show()
                'If My.Settings.FullscreenClose = True Then
                ctlPlayer.Video.ToggleFullScreen()
                'End If
            Catch EntryPointNotFoundException As Exception
            End Try
        End If
    End Sub

    Private Sub Main_Activated(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Activated
        frmFscreen.Close()
    End Sub

    Private Sub tabLWL_Enter(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tabPodcasts.Enter
        Me.Size = New System.Drawing.Size(625, 526)
    End Sub

    Private Sub btnUpdates_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnUpdates.Click, niUpdate.Click
        Try
            Dim Proc As New System.Diagnostics.Process
            Proc.StartInfo.WorkingDirectory = "updater\"
            Proc.StartInfo.FileName = "MeaUpdater.exe"
            Proc.Start()
            Me.Close()
        Catch ex As Exception

            Dim CustomError As String
            If VistaControls.OsSupport.IsVistaOrBetter = True Then
                CustomError = "UAC may have disalowed the MeaUpdate Utility from opening"
            Else
                CustomError = "Unable to locate MeaUpdate"
            End If
            Dim CustomUserDo As String
            If VistaControls.OsSupport.IsVistaOrBetter = True Then
                CustomUserDo = "Please accept the UAC promt to launch MeaUpdate." & vbCrLf & "If no UAC promt was shown or you accpeted the UAC promt then please reinstall MeaMod Playme to restore the MeaUpdate Utility"
            Else
                CustomUserDo = "Please reinstall MeaMod Playme to restore the MeaUpdate Utility"
            End If

            If My.Settings.ErrorReporting = True Then
                HandledExceptionManager.EmailError = True
            ElseIf My.Settings.ErrorReporting = False Then
                HandledExceptionManager.EmailError = False
            End If
            HandledExceptionManager.ShowDialog(CustomError, _
                   "You will not be able to update MeaMod Playme", _
                   CustomUserDo, _
                   ex, _
                    MessageBoxButtons.OK, _
                   MessageBoxIcon.Error, _
                   HandledExceptionManager.UserErrorDefaultButton.Default)
        End Try
    End Sub

    Private Sub btnInternetCheck_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnInternetCheck.Click, niInternetCheck.Click
        Dim s As Thread
        s = New Thread(AddressOf frmNetCheck.ShowDialog)
        s.Start()
        'frmNetCheck.ShowDialog()
    End Sub

    Private Sub btnInternetOptions_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnInternetOptions.Click
        Try
            Dim Proc As New System.Diagnostics.Process
            Proc.StartInfo.FileName = "inetcpl.cpl"
            Proc.Start()
        Catch ex As Exception
            MessageBox.Show("Unable to open Internet Options", "An error has occurred", MessageBoxButtons.OK, MessageBoxIcon.Error)
        End Try
    End Sub

    Private Sub trackVolume_Scroll(ByVal sender As System.Object, ByVal e As System.Windows.Forms.ScrollEventArgs) Handles trackVolume.Scroll
        ctlPlayer.Audio.Volume = trackVolume.Value
        If trackVolume.Value >= 50 Then
            btnMute2.Image = My.Resources.Resources.resSound_full
        ElseIf trackVolume.Value <= 1 Then
            btnMute2.Image = My.Resources.Resources.resSound_none
        ElseIf trackVolume.Value <= 49 Then
            btnMute2.Image = My.Resources.Resources.resSound_low
        End If
    End Sub

    Private Sub btnMute2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnMute2.Click
        If ctlPlayer.Audio.Mute = False Then
            ctlPlayer.Audio.Mute = True
        ElseIf ctlPlayer.Audio.Mute = True Then
            ctlPlayer.Audio.Mute = False
        End If
        If ctlPlayer.Audio.Mute = True Then
            btnMute2.Image = My.Resources.Resources.resSound_mute
            btnMute2.ImageAlign = ContentAlignment.MiddleLeft
            GoTo checkEnd
        End If
        If ctlPlayer.Audio.Mute = False Then
            If trackVolume.Value >= 50 Then
                btnMute2.Image = My.Resources.Resources.resSound_full
            ElseIf trackVolume.Value <= 1 Then
                btnMute2.Image = My.Resources.Resources.resSound_none
            ElseIf trackVolume.Value <= 49 Then
                btnMute2.Image = My.Resources.Resources.resSound_low
            End If
            GoTo checkEnd
        End If
checkEnd:
    End Sub

    Private Sub tagArt_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tagArt.Click
        frmCoverArt.Show()
    End Sub

    Private Sub frmMain_FormClosing(ByVal sender As System.Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles MyBase.FormClosing
        StopEvent()
        Call SetMusicInfo("", "", "", , , False)
        If My.Settings.LastFM = True Then
            SerializarScrobblingCache()
        End If
        Vlc.Dispose()
        ctlPlayer.Dispose()
    End Sub

    Private Sub ExitToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles niExit.Click
        Me.Close()
    End Sub

    Private Sub niControl_DoubleClick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles niControl.DoubleClick
        If Me.WindowState = FormWindowState.Normal Then
            Me.WindowState = FormWindowState.Minimized
            Me.ShowInTaskbar = False
        ElseIf Me.WindowState = FormWindowState.Minimized Then
            Me.WindowState = FormWindowState.Normal
            Me.ShowInTaskbar = True
        End If
    End Sub

    Private Sub niCoverart_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles niCoverart.Click
        frmCoverArt.Show()
    End Sub

    Private Sub niHelpRemote_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles niHelpRemote.Click
        niControl.ShowBalloonTip(10, "MeaMod Playme", "Double Click = Show/Hide Player" & vbNewLine & "Right Click = Show Remote Menu", ToolTipIcon.Info)
    End Sub

    Private Sub btnFeedback_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnFeedback.Click, niFeedBack.Click

        If CStr(CheckConn.IsConnected()) = False Then
            Dim vd As New VDialog()
            With vd
                .WindowTitle = "No Internet Connection"
                .MainIcon = VDialogIcon.Information
                .Buttons = New VDialogButton() {New VDialogButton(VDialogResult.OK)}
                .DefaultButton = VDialogDefaultButton.Button1
                .MainInstruction = "No Internet Conntection Detected"
                .Content = "The Component that you are trying to access" + vbNewLine + "requires an internet connection"
                .Sound = VDialogSound.Error
                .Show()
            End With
        ElseIf CStr(CheckConn.IsConnected()) = True Then
            'frmFeedback.Show()
            With New MeaModReporter
                .SubmitterPath = "https://meamod.com/meamodreporter/meamodplayme"
                .ApplicationVersion = GetAppVersion("[M].[m].[b].[r]")
                .ShowDialog()
            End With
        End If
    End Sub

    Private Sub btnOptions_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnOptions.Click
        frmOptions.ShowDialog()
    End Sub

    Private Sub btnEAC_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles niEAC.Click, btnEAC.Click
        If VistaControls.OsSupport.IsVistaOrBetter = True Then
            frmAudioControl.Show()
        Else
            MessageBox.Show("Playme Audio Control requires Windows Vista", "Playme Audio Control", MessageBoxButtons.OK, MessageBoxIcon.Error)
        End If
    End Sub

    Private Sub stYouTube_SearchStarted(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles stYouTube.SearchStarted
        wbYouTube.Navigate("http://youtube.com/results?search_query=" + stYouTube.Text)
        'wbYouTube.Navigate("http://media.ogo.ms/youtube/?tag=" + stYouTube.Text)
    End Sub

    Private Sub tabYouTube_Enter(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tabYouTube.Enter
        Me.Size = New System.Drawing.Size(950, 600)
        pbWeb.Visible = True
        wbYouTube.DocumentText = YouTubeSearchMaster()
    End Sub

    Private Sub wbYouTube_ProgressChanged(ByVal sender As System.Object, ByVal e As System.Windows.Forms.WebBrowserProgressChangedEventArgs) Handles wbYouTube.ProgressChanged
        pbWeb.Maximum = e.MaximumProgress
        pbWeb.Value = e.CurrentProgress
    End Sub

    Private Sub tabYouTube_Leave(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tabYouTube.Leave
        pbWeb.Visible = False
    End Sub

    Private Sub stYouTube_SearchCancelled(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles stYouTube.SearchCancelled
        wbYouTube.DocumentText = YouTubeSearchMaster()
    End Sub

    Function YouTubeSearchMaster()
        Dim var As String = "<!DOCTYPE html PUBLIC '-//W3C//DTD XHTML 1.0 Transitional//EN' 'http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd'><html xmlns='http://www.w3.org/1999/xhtml'><head><meta content='text/html; charset=utf-8' http-equiv='Content-Type' /><title>YouTube Loader</title><style type='text/css'>.style1 {font-family: Arial, Helvetica, sans-serif;}</style></head><body><h1 class='style1'>Please enter search term</h1><p><img alt='YouTube Logo' height='91' src='http://media.ogo.ms/youtube/youtube-logo.png' width='269' /></p></body></html>"
        Return var
    End Function

    Private Sub btnMywnplayer_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnMywnplayer.Click
        frmMywnMusicStreamer.Show()
    End Sub

    Private Sub btnInternetSpeed_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnInternetSpeed.Click, niInternetSpeed.Click
        frmInternetSpeed.Show()
    End Sub

    Private Sub btnAddon_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAddon.Click
        'If folderExists = True And (fileExists = True Or fileExistsJar = True) Then
        'If fileExists = True Then
        'System.Diagnostics.Process.Start("addons\custom\plugin.exe")
        'ElseIf fileExistsJar = True Then
        'System.Diagnostics.Process.Start("addons\custom\plugin.jar")
        'End If
        'End If
    End Sub

    Private Sub sbProcess_MouseDown(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles sbProcess.MouseDown
        If ctlPlayer.State = VlcState.Playing Then
            ctlPlayer.Position = sbProcess.Value / 1000
        End If
    End Sub

    Private Sub tagFilename_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tagFilename.Click
        If InfoTag.Tag.Title > "" Or InfoTag.Tag.FirstPerformer > "" Then
            NotifierInfo.Info = tagFilename.Text
            NotifierInfo.Interval = 100
            NotifierInfo.TimeOut = 5
            NotifierInfo.ShowInfo()
        End If
    End Sub

    Private Sub btnControlTaskbar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnControlTaskbar.Click
        frmWinTaskDemo.Show()
    End Sub

    Public Sub StopEvent()
        ctlPlayer.Stop()
        btnStopn.Enabled = False
    End Sub

    Public Sub OpnFile(ByVal OpenFile As String)
        'StopEvent()
        imgBolt.Visible = False
        imgStreamimg.Enabled = False
        imgStreamimg.Visible = False
        tagFilename.Visible = True
        tagTime.Visible = True
        Dim desc As VlcMedia = Vlc.NewMedia(OpenFile)
        ctlPlayer.Load(desc)
        desc.Dispose()
        ctlPlayer.Play()
        tabcMain.SelectTab("tabPlayer")
        tagFilename.Text = OpenFile
        TrackName = OpenFile
        'tagArt.Image = noCoverArt
        Try
            InfoTag = TagLib.File.Create(OpenFile)
            If InfoTag.Tag.Pictures.Length > 0 Then
                For Each picture As TagLib.IPicture In InfoTag.Tag.Pictures
                    If picture.Type = TagLib.PictureType.FrontCover Then
                        tagArt.Enabled = True
                        tagArt.Visible = True
                        Dim stream As New IO.MemoryStream(picture.Data.Data)
                        Dim Image As New Bitmap(stream)
                        tagArt.Image = Image
                        niCoverart.Image = Image
                        Exit For
                    End If
                Next
            Else
                SetTheme(True)
            End If
        Catch UnsupportedFormatException As Exception
        End Try
        LastTotalLength = ctlPlayer.Length
        Dim filename As String = OpenFile.ToLower
        Dim isAudio As Boolean = filename.EndsWith("mp3") OrElse filename.EndsWith("wma") OrElse filename.EndsWith("m4a") OrElse filename.EndsWith("m4b") OrElse filename.EndsWith("m4p") OrElse filename.EndsWith("wav") OrElse filename.EndsWith("ogg") OrElse filename.EndsWith("AAC") OrElse filename.EndsWith("aiff") OrElse filename.EndsWith("mka") OrElse filename.EndsWith("flac") OrElse filename.EndsWith("ac3")
        Dim isVideo As Boolean = filename.EndsWith("avi") OrElse filename.EndsWith("mkv") OrElse filename.EndsWith("mpg") OrElse filename.EndsWith("mpeg") OrElse filename.StartsWith("dvd://")
        If isAudio Then
            Me.Size = New System.Drawing.Size(625, 178)
            Try
                tagFilename.Text = InfoTag.Tag.FirstPerformer & " - " & InfoTag.Tag.Title

                If InfoTag.Tag.FirstPerformer.Length > 0 Or InfoTag.Tag.Title.Length > 0 Then
                    If My.Settings.MediaInfo = True Then
                        NotifierInfo.Info = tagFilename.Text
                        NotifierInfo.Interval = 100
                        NotifierInfo.TimeOut = 5
                        NotifierInfo.ShowInfo()
                    End If
                    If My.Settings.Lyrics = True Then
                        Dim t As Thread
                        t = New Thread(AddressOf LyricsThread)
                        t.Start()
                    End If

                    If My.Settings.LastFM = True Then
                        Dim s As Thread
                        s = New Thread(AddressOf LastfmScrobble)
                        s.Start()
                    End If
                    pbBuyNow.Visible = True
                    'rtbLy.Text = GetLyrics(InfoTag.Tag.FirstPerformer.Replace("'", ""), InfoTag.Tag.Title.Replace("'", ""))
                    'rtbLy.Text = MusicBrainzLookup(InfoTag.Tag.FirstPerformer & " " & InfoTag.Tag.Title)
                    'RunDiscogsAPIFunction("http://www.discogs.com/artist/" & InfoTag.Tag.FirstPerformer & "?f=xml&api_key=" & ConstrStrAPIKey)
                End If
                Call SetMusicInfo(InfoTag.Tag.Title, InfoTag.Tag.FirstPerformer, InfoTag.Tag.FirstPerformer & " - " & InfoTag.Tag.Title)
                If InfoTag.Tag.Pictures.Length > 0 Then
                    For Each picture As TagLib.IPicture In InfoTag.Tag.Pictures
                        If picture.Type = TagLib.PictureType.FrontCover Then
                            tagArt.Enabled = True
                            tagArt.Visible = True
                            Dim stream As New IO.MemoryStream(picture.Data.Data)
                            Dim Image As New Bitmap(stream)
                            tagArt.Image = Image
                            niCoverart.Image = Image
                            Exit For
                        End If
                    Next
                Else
                    SetTheme(True)
                End If

            Catch NullReferenceException As Exception
            End Try
        ElseIf isVideo Then
            Me.Size = New System.Drawing.Size(625, 526)
            tagTime.Visible = True
        ElseIf PlayFolder = True Then
            'Me.Size = New System.Drawing.Size(625, 178)
            tagFilename.Text = "Playing Folder: " & OpenFile
        Else
        End If
    End Sub

    Public Function TimeString(ByRef Seconds As Integer, Optional ByRef Verbose As Boolean = False) As String

        'if verbose = false, returns
        'something like
        '02:22.08
        'if true, returns
        '2 hours, 22 minutes, and 8 seconds

        Dim lHrs As Integer
        Dim lMinutes As Integer
        Dim lSeconds As Integer

        lSeconds = Seconds

        lHrs = Int(lSeconds / 3600)
        lMinutes = (Int(lSeconds / 60)) - (lHrs * 60)
        lSeconds = Int(lSeconds Mod 60)

        Dim sAns As String


        If lSeconds = 60 Then
            lMinutes = lMinutes + 1
            lSeconds = 0
        End If

        If lMinutes = 60 Then
            lMinutes = 0
            lHrs = lHrs + 1
        End If

        sAns = String.Format("{0:00}", lHrs) & ":" & String.Format("{0:00}", lMinutes) & ":" & String.Format("{0:00}", lSeconds)

        TimeString = sAns

    End Function

    Public Function TimeString2(ByRef Seconds As Integer, Optional ByRef Verbose As Boolean = False) As String

        'if verbose = false, returns
        'something like
        '02:22.08
        'if true, returns
        '2 hours, 22 minutes, and 8 seconds

        Dim lHrs As Integer
        Dim lMinutes As Integer
        Dim lSeconds As Integer

        lSeconds = Seconds

        lHrs = Int(lSeconds / 3600)
        lMinutes = (Int(lSeconds / 60)) - (lHrs * 60)
        lSeconds = Int(lSeconds Mod 60)

        Dim sAns As String


        If lSeconds = 60 Then
            lMinutes = lMinutes + 1
            lSeconds = 0
        End If

        If lMinutes = 60 Then
            lMinutes = 0
            lHrs = lHrs + 1
        End If

        sAns = String.Format("{0:00}", lHrs) & ":" & String.Format("{0:00}", lMinutes) & ":" & String.Format("{0:00}", lSeconds)

        TimeString2 = sAns

    End Function

    Private Sub tsVideoChoice_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tsVideoChoice.Click
        My.Settings.Reload()
        If My.Settings.VideoPro = "YouTube" Then
            System.Diagnostics.Process.Start("http://youtube.com/results?search_query=" + tagFilename.Text)
        ElseIf My.Settings.VideoPro = "Yahoo Music" Then
            System.Diagnostics.Process.Start("http://search.music.yahoo.com/search/?m=video&p=" + tagFilename.Text)
        ElseIf My.Settings.VideoPro = "AOL Music" Then
            System.Diagnostics.Process.Start("http://music.aol.com/search/?cat=video&query=" + tagFilename.Text)
        ElseIf My.Settings.VideoPro = "MTV Video" Then
            System.Diagnostics.Process.Start("http://www.mtv.com/search/?requiredfields=mtv_st%3Avideo&x=0&y=0&searchterm=" + tagFilename.Text)
        ElseIf My.Settings.VideoPro = "last.fm" Then
            System.Diagnostics.Process.Start("http://www.last.fm/search?m=all&q=" + tagFilename.Text)
        End If
    End Sub

    Private Sub tabLyrics_Enter(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tabLyrics.Enter
        Me.Size = New System.Drawing.Size(625, 526)
    End Sub

    Function MusicBrainzLookup(ByVal strArtist As String)
        Return Nothing
    End Function

    Private Sub btnAdvOpenMenu_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAdvOpenMenu.Click
        frmAdvOpen.ShowDialog()
    End Sub

    Private Sub btnOpenDisc_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnOpenDisc.Click, btnOpenDiskN.Click
        frmAdvOpen.LoadTab(1)
        frmAdvOpen.ShowDialog()
    End Sub

    Private Sub btnOpenNetworkMenu_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnOpenNetworkMenu.Click
        frmAdvOpen.LoadTab(2)
        frmAdvOpen.ShowDialog()
    End Sub

    Private Sub btnOpenFolderMenu_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnOpenFolderMenu.Click
        Dim DidWork As Integer = diaOpenFolder.ShowDialog()
        If DidWork = DialogResult.Cancel Then
        Else
            PlayFolder = True
            OpnFile(diaOpenFolder.SelectedPath)
        End If
    End Sub

    Private Function zzzzzzz(ByVal fileName As String) As String
        Dim cmdLineProcess As New Process()
        cmdLineProcess.StartInfo.FileName = "genpuid"
        cmdLineProcess.StartInfo.RedirectStandardOutput = True
        cmdLineProcess.StartInfo.UseShellExecute = False
        cmdLineProcess.StartInfo.CreateNoWindow = True

        Dim arguments As String = "{0} -xml -rmd=2 ""{1}"""
        cmdLineProcess.StartInfo.Arguments = [String].Format(arguments, "44157831fb9fdcbb631133d6ab81212c", fileName)

        cmdLineProcess.Start()
        cmdLineProcess.PriorityClass = ProcessPriorityClass.BelowNormal
        Dim result As String = cmdLineProcess.StandardOutput.ReadToEnd()
        ' have to read 
        ' before waiting!
        cmdLineProcess.WaitForExit()
        cmdLineProcess = Nothing
        Return result
    End Function

    Private Sub btnPlaymeWebsite_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnPlaymeWebsite.Click
        Try
            Dim Proc As New System.Diagnostics.Process
            Proc.StartInfo.FileName = "http://getplayme.com"
            Proc.Start()
        Catch ex As Exception

            Dim CustomError As String
            CustomError = "Unable to launch the MeaMod Playme website"
            Dim CustomUserDo As String
            CustomUserDo = "Please check you have a default web browser"
            If My.Settings.ErrorReporting = True Then
                HandledExceptionManager.EmailError = True
            ElseIf My.Settings.ErrorReporting = False Then
                HandledExceptionManager.EmailError = False
            End If
            HandledExceptionManager.ShowDialog(CustomError, _
                   "Please visit http://getplayme.com in you web browser", _
                   CustomUserDo, _
                   ex, _
                    MessageBoxButtons.OK, _
                   MessageBoxIcon.Error, _
                   HandledExceptionManager.UserErrorDefaultButton.Default)
        End Try
    End Sub

    Public Sub LastfmHandshake()
        DesSerializarScrobblingCache()
        My.Settings.Reload()
        LastfmScrobbler.Handshake(My.Settings.LastFMUsr, My.Settings.LastFMPass, HardFailure)
        If HardFailure = True Then
            MsgBox("last.fm handshake failed")
            Exit Sub
        End If
        'AddHandler LastfmScrobbler.ProcessEnded, AddressOf ScrobblingEnded
    End Sub

    Private Sub LastfmScrobble()
        Song = New BasicSongData(InfoTag.Tag.FirstPerformer, InfoTag.Tag.Album, InfoTag.Tag.Title, InfoTag.Tag.Track)
        LastfmScrobbler.Handshake(My.Settings.LastFMUsr, My.Settings.LastFMPass, HardFailure)
        'If HardFailure = True Then
        'MsgBox("last.fm handshake failed")
        'Exit Sub
        'End If
        Song.LengthInSeconds = ctlPlayer.Length / 1000
        Song.UnixTimestampTrackStartedPlaying = General.GetUnixTimeSpamp(Now)
        LastfmScrobbler.SendNowPlayingNotification(Song)
    End Sub

    Private Delegate Sub DSetText(ByVal Text As String)

    Private Sub ScrobblingEnded()
        Dim D As New DSetText(AddressOf lfSetText)
        Try
            rtbLFL.Invoke(D, LastfmScrobbler.Log)
        Catch InvalidOperationException As Exception

        End Try
    End Sub

    Private Sub lfSetText(ByVal Text As String)
        rtbLFL.Text = Text
        frmOptions.CallLastFMlog()
    End Sub

    Private Sub LyricsThread()
        Dim NewText As String
        'NewText = (GetLyrics(InfoTag.Tag.FirstPerformer.Replace("'", ""), InfoTag.Tag.Title.Replace("'", ""), InfoTag))
        NewText = (GetLyrics(InfoTag))

        ' Check if this method is running on a different thread
        ' than the thread that created the control.
        If Me.rtbLy.InvokeRequired Then
            ' It's on a different thread, so use Invoke.
            Dim d As New SetTextCallback(AddressOf SetText)
            Me.Invoke(d, New Object() {[NewText]})
        Else
            ' It's on the same thread, no need for Invoke.
            Me.rtbLy.Text = NewText
        End If
    End Sub

    Private Sub LyricsThreadFetch()
        Dim NewText As String
        'NewText = (GetLyrics(InfoTag.Tag.FirstPerformer.Replace("'", ""), InfoTag.Tag.Title.Replace("'", ""), InfoTag))
        NewText = (GetLyrics(InfoTag, True))

        ' Check if this method is running on a different thread
        ' than the thread that created the control.
        If Me.rtbLy.InvokeRequired Then
            ' It's on a different thread, so use Invoke.
            Dim d As New SetTextCallback(AddressOf SetText)
            Me.Invoke(d, New Object() {[NewText]})
        Else
            ' It's on the same thread, no need for Invoke.
            Me.rtbLy.Text = NewText
        End If
    End Sub

    Private Sub SetText(ByVal [text] As String)
        Me.rtbLy.Text = [text]
    End Sub

    Private Sub btnAudioControlPremium_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAudioControlPremium.Click
        If VistaControls.OsSupport.IsVistaOrBetter = True Then
            frmAudioControlPremium.Show()
        Else
            MessageBox.Show("Playme Audio Control Premium requires Windows Vista", "Playme Audio Control Premium", MessageBoxButtons.OK, MessageBoxIcon.Error)
        End If
    End Sub

    Public Sub SetTheme(Optional ByVal OV As Boolean = False)
ifl:
        If My.Settings.Theme = "Default" Then
            KryptonManager.GlobalPalette = ThemeWhite
            noCoverArt = MeaMod_Playme.My.Resources.resNocoverartblack
            If ctlPlayer.State <> VlcState.Playing Or OV = True Then
                tagArt.Image = noCoverArt
                niCoverart.Image = MeaMod_Playme.My.Resources.resNocoverartblack
            End If
            tabPlayer.BackColor = Color.Transparent
        ElseIf My.Settings.Theme = "NewBlue" Then
            KryptonManager.GlobalPalette = ComponentFactory.Krypton.Toolkit.KryptonManager.PaletteSparkleBlue
            noCoverArt = MeaMod_Playme.My.Resources.resNocoverartwhite
            If ctlPlayer.State <> VlcState.Playing Or OV = True Then
                tagArt.Image = noCoverArt
                niCoverart.Image = MeaMod_Playme.My.Resources.resNocoverartblack
            End If
            tabPlayer.BackColor = Color.Transparent
        ElseIf My.Settings.Theme = "IceBlue" Then
            KryptonManager.GlobalPalette = ComponentFactory.Krypton.Toolkit.KryptonManager.PaletteOffice2007Blue
            noCoverArt = MeaMod_Playme.My.Resources.resNocoverartblack
            If ctlPlayer.State <> VlcState.Playing Or OV = True Then
                tagArt.Image = noCoverArt
                niCoverart.Image = MeaMod_Playme.My.Resources.resNocoverartblack
            End If
            tabPlayer.BackColor = Color.Transparent
        ElseIf My.Settings.Theme = "Graphite" Then
            KryptonManager.GlobalPalette = ComponentFactory.Krypton.Toolkit.KryptonManager.PaletteOffice2007Black
            noCoverArt = MeaMod_Playme.My.Resources.resNocoverartwhite
            If ctlPlayer.State <> VlcState.Playing Or OV = True Then
                tagArt.Image = noCoverArt
                niCoverart.Image = MeaMod_Playme.My.Resources.resNocoverartblack
            End If
            tabPlayer.BackColor = Color.Transparent
        ElseIf My.Settings.Theme = "Graphite 2010" Then
            KryptonManager.GlobalPalette = ComponentFactory.Krypton.Toolkit.KryptonManager.PaletteOffice2010Black
            noCoverArt = MeaMod_Playme.My.Resources.resNocoverartwhite
            If ctlPlayer.State <> VlcState.Playing Or OV = True Then
                tagArt.Image = noCoverArt
                niCoverart.Image = MeaMod_Playme.My.Resources.resNocoverartblack
            End If
            tabPlayer.BackColor = Color.Transparent
        ElseIf My.Settings.Theme = "White" Then
            My.Settings.Theme = "Default"
            My.Settings.Save()
            My.Settings.Reload()
            GoTo ifl
        ElseIf My.Settings.Theme = "Purple" Then
            KryptonManager.GlobalPalette = ThemePurple
            noCoverArt = MeaMod_Playme.My.Resources.resNocoverartblack
            If ctlPlayer.State <> VlcState.Playing Or OV = True Then
                tagArt.Image = noCoverArt
                niCoverart.Image = MeaMod_Playme.My.Resources.resNocoverartblack
            End If
            tabPlayer.BackColor = Color.Transparent
        ElseIf My.Settings.Theme = "Classic" Then
            KryptonManager.GlobalPalette = ComponentFactory.Krypton.Toolkit.KryptonManager.PaletteProfessionalSystem
            noCoverArt = MeaMod_Playme.My.Resources.resNocoverartblack
            If ctlPlayer.State <> VlcState.Playing Or OV = True Then
                tagArt.Image = noCoverArt
                niCoverart.Image = MeaMod_Playme.My.Resources.resNocoverartblack
            End If
            tabPlayer.BackColor = Color.Transparent
        Else
            My.Settings.Theme = "Default"
            My.Settings.Save()
            My.Settings.Reload()
            GoTo ifl
        End If
        My.Settings.Save()
    End Sub

    Private Sub ActivatePremiumToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ActivatePremiumToolStripMenuItem.Click
        frmPremium.Show()
    End Sub

    Private Sub tabPlayer_Enter(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tabPlayer.Enter
        Dim filename As String
        If ctlPlayer.State = VlcState.Playing Then
            If My.Application.CommandLineArgs.Count = 1 Then
                filename = My.Application.CommandLineArgs(0).ToLower()
            Else
                filename = diaOpenFile.FileName.ToLower()
            End If
            Dim isAudio As Boolean = filename.EndsWith("mp3") OrElse filename.EndsWith("wma") OrElse filename.EndsWith("m4a") OrElse filename.EndsWith("m4b") OrElse filename.EndsWith("m4p") OrElse filename.EndsWith("wav") OrElse filename.EndsWith("ogg") OrElse filename.EndsWith("AAC") OrElse filename.EndsWith("aiff") OrElse filename.EndsWith("mka") OrElse filename.EndsWith("flac") OrElse filename.EndsWith("ac3")
            Dim isVideo As Boolean = filename.EndsWith("avi") OrElse filename.EndsWith("mkv") OrElse filename.EndsWith("m4v") OrElse filename.EndsWith("mpeg")
            If isAudio Then
                Me.Size = New System.Drawing.Size(625, 178)
                Try
                    tagFilename.Text = InfoTag.Tag.FirstPerformer & " - " & InfoTag.Tag.Title
                    Call SetMusicInfo(InfoTag.Tag.Title, InfoTag.Tag.FirstPerformer, InfoTag.Tag.FirstPerformer & " - " & InfoTag.Tag.Title)
                    For Each picture As TagLib.IPicture In InfoTag.Tag.Pictures
                        If picture.Type = TagLib.PictureType.FrontCover Then
                            tagArt.Enabled = True
                            tagArt.Visible = True
                            Dim stream As New IO.MemoryStream(picture.Data.Data)
                            tagArt.Image = New Bitmap(stream)
                            niCoverart.Image = New Bitmap(stream)
                            Exit For
                        End If
                    Next
                Catch NullPointerException As Exception
                End Try
            ElseIf isVideo Then
                Me.Size = New System.Drawing.Size(625, 526)
                Try
                    tagFilename.Text = InfoTag.Tag.FirstPerformer & " - " & InfoTag.Tag.Title
                    Call SetMusicInfo(InfoTag.Tag.Title, InfoTag.Tag.FirstPerformer, InfoTag.Tag.FirstPerformer & " - " & InfoTag.Tag.Title)
                    For Each picture As TagLib.IPicture In InfoTag.Tag.Pictures
                        If picture.Type = TagLib.PictureType.FrontCover Then
                            tagArt.Enabled = True
                            tagArt.Visible = True
                            Dim stream As New IO.MemoryStream(picture.Data.Data)
                            tagArt.Image = New Bitmap(stream)
                            niCoverart.Image = New Bitmap(stream)
                            Exit For
                        End If
                    Next
                Catch NullPointerException As Exception
                End Try
            Else
            End If
        Else
            Me.Size = New System.Drawing.Size(625, 178)
        End If
    End Sub

    Private Sub pbAdvert_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles pbAdvert.Click
        Dim Proc As New System.Diagnostics.Process
        Proc.StartInfo.FileName = AdvertURL
        Proc.Start()
    End Sub

    Private Sub tsLyricsReload_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tsLyricsReload.Click
        rtbLy.Clear()
        If My.Settings.Lyrics = True Then
            Dim t As Thread
            t = New Thread(AddressOf LyricsThread)
            t.Start()
        End If
    End Sub

    Private Sub tsSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tsSave.Click
        SaveLyricsTag(InfoTag, rtbLy.Text)
    End Sub

    Private Sub tsClear_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tsClear.Click
        ClearLyricsTag(InfoTag)
    End Sub

    Private Sub tsFetch_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tsFetch.Click
        rtbLy.Clear()
        If My.Settings.Lyrics = True Then
            Dim t As Thread
            t = New Thread(AddressOf LyricsThreadFetch)
            t.Start()
        End If
    End Sub

    Private Sub tabHome_Enter(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tabHome.Enter
        Me.Size = New System.Drawing.Size(1001, 860)
    End Sub

    Private Sub pbBuyNow_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles pbBuyNow.Click
        wbHome.Navigate("http://download.le.meamod.com/meamodplayme/store/amazon_store?SearchIndex=Music&Keywords=" & InfoTag.Tag.FirstPerformer & " - " & InfoTag.Tag.Album)
        tabcMain.SelectTab("tabHome")
    End Sub
End Class


